﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mofang.Utils.LogProvider
{
    public interface ILogHelper
    {
        void SaveLog(LogModel log);

        ICommonLog BuildLog(LogModel log);

    }

    public class LogHelper : ILogHelper
    {
        public void SaveLog(LogModel log)
        {
            var entity = BuildLog(log);

            var type = entity.GetType();

            var logRep = new LogRepository<ICommonLog>();

            logRep.Insert(entity);
        }


        /// <summary>
        /// 获取日志
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public virtual ICommonLog BuildLog(LogModel log)
        {
            var type = (OperateTypes.LogType)log.Type;

            var typeName = type.ToString("g");

            var operation = OperationReader.Instance.ReadOperate(log.Operate, typeName);

            switch (type)
            {
                case OperateTypes.LogType.OrderLog:
                    return new OrderLog(log, operation);
                case OperateTypes.LogType.RoomLog:
                    return new RoomLog(log, operation);
                case OperateTypes.LogType.MessageLog:
                    return new MessageLog(log, operation);
                default:
                    return new CommonLog(log, operation);
            }
        }


    }



}
